|
mcurrentsens 2.2.0
|
API for configuring and manipulating mCurrent Sens Click driver. More...
Topics | |
| mCurrent Sens Registers List | |
| List of registers of mCurrent Sens Click driver. | |
| mCurrent Sens Registers Settings | |
| Settings for registers of mCurrent Sens Click driver. | |
| mCurrent Sens MikroBUS Map | |
| MikroBUS pin mapping of mCurrent Sens Click driver. | |
Functions | |
| void | mcurrentsens_cfg_setup (mcurrentsens_cfg_t *cfg) |
| mCurrent Sens configuration object setup function. | |
| err_t | mcurrentsens_init (mcurrentsens_t *ctx, mcurrentsens_cfg_t *cfg) |
| mCurrent Sens initialization function. | |
| err_t | mcurrentsens_default_cfg (mcurrentsens_t *ctx) |
| mCurrent Sens default configuration function. | |
| err_t | mcurrentsens_write_reg (mcurrentsens_t *ctx, uint8_t reg, uint8_t data_in) |
| mCurrent Sens write register function. | |
| err_t | mcurrentsens_read_reg (mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_out) |
| mCurrent Sens read register function. | |
| err_t | mcurrentsens_write_regs (mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len) |
| mCurrent Sens write multiple registers function. | |
| err_t | mcurrentsens_read_regs (mcurrentsens_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len) |
| mCurrent Sens read multiple registers function. | |
| err_t | mcurrentsens_write_reg16 (mcurrentsens_t *ctx, uint8_t reg, uint16_t data_in) |
| mCurrent Sens write 16-bit register function. | |
| err_t | mcurrentsens_read_reg16 (mcurrentsens_t *ctx, uint8_t reg, uint16_t *data_out) |
| mCurrent Sens read 16-bit register function. | |
| err_t | mcurrentsens_write_reg24 (mcurrentsens_t *ctx, uint8_t reg, uint32_t data_in) |
| mCurrent Sens write 24-bit register function. | |
| err_t | mcurrentsens_read_reg24 (mcurrentsens_t *ctx, uint8_t reg, uint32_t *data_out) |
| mCurrent Sens read 24-bit register function. | |
| err_t | mcurrentsens_send_fast_cmd (mcurrentsens_t *ctx, uint8_t cmd) |
| mCurrent Sens send fast command function. | |
| err_t | mcurrentsens_check_com (mcurrentsens_t *ctx) |
| mCurrent Sens communication check function. | |
| err_t | mcurrentsens_set_mux (mcurrentsens_t *ctx, uint8_t vin_p, uint8_t vin_n) |
| mCurrent Sens set MUX function. | |
| err_t | mcurrentsens_set_gain (mcurrentsens_t *ctx, uint8_t gain) |
| mCurrent Sens set gain function. | |
| err_t | mcurrentsens_set_osr (mcurrentsens_t *ctx, uint8_t osr) |
| mCurrent Sens set OSR function. | |
| err_t | mcurrentsens_set_mode (mcurrentsens_t *ctx, uint8_t mode) |
| mCurrent Sens set mode function. | |
| err_t | mcurrentsens_get_irq (mcurrentsens_t *ctx, uint8_t *data_out) |
| mCurrent Sens get IRQ function. | |
| err_t | mcurrentsens_set_offset_cal (mcurrentsens_t *ctx, int32_t data_in) |
| mCurrent Sens set offset calibration function. | |
| err_t | mcurrentsens_get_offset_cal (mcurrentsens_t *ctx, int32_t *data_out) |
| mCurrent Sens get offset calibration function. | |
| err_t | mcurrentsens_set_gain_cal (mcurrentsens_t *ctx, uint32_t data_in) |
| mCurrent Sens set gain calibration function. | |
| err_t | mcurrentsens_get_gain_cal (mcurrentsens_t *ctx, uint32_t *data_out) |
| mCurrent Sens get gain calibration function. | |
| err_t | mcurrentsens_en_dig_cal (mcurrentsens_t *ctx, uint8_t en_offset, uint8_t en_gain) |
| mCurrent Sens enable digital calibration function. | |
| err_t | mcurrentsens_apply_calib (mcurrentsens_t *ctx, mcurrentsens_calib_t cal) |
| mCurrent Sens apply channel calibration function. | |
| err_t | mcurrentsens_wait_data_ready (mcurrentsens_t *ctx) |
| mCurrent Sens wait data ready function. | |
| err_t | mcurrentsens_read_adc (mcurrentsens_t *ctx, int32_t *data_out) |
| mCurrent Sens read ADC data function. | |
| err_t | mcurrentsens_read_adc_avg (mcurrentsens_t *ctx, uint8_t sample_count, int32_t *data_out) |
| mCurrent Sens read averaged ADC function. | |
| err_t | mcurrentsens_read_voltage_avg (mcurrentsens_t *ctx, uint8_t sample_count, float *data_out) |
| mCurrent Sens read averaged voltage function. | |
| err_t | mcurrentsens_read_ch1_current (mcurrentsens_t *ctx, float *data_out) |
| mCurrent Sens read channel 1 current function. | |
| err_t | mcurrentsens_read_ch1_voltage (mcurrentsens_t *ctx, float *data_out) |
| mCurrent Sens read channel 1 voltage function. | |
| err_t | mcurrentsens_read_ch2_current (mcurrentsens_t *ctx, float *data_out) |
| mCurrent Sens read channel 2 current function. | |
| err_t | mcurrentsens_read_ch2_voltage (mcurrentsens_t *ctx, float *data_out) |
| mCurrent Sens read channel 2 voltage function. | |
| err_t | mcurrentsens_read_temperature (mcurrentsens_t *ctx, float *data_out) |
| mCurrent Sens read temperature function. | |
| float | mcurrentsens_adc_to_mv (int32_t adc_code, float gain_adc) |
| mCurrent Sens convert ADC code to millivolts function. | |
| void | mcurrentsens_calculate_calib (mcurrentsens_calib_t *calib, float offset_coeff, float target_1, float measured_1, float target_2, float measured_2) |
| mCurrent Sens calculate calibration function. | |
| err_t | mcurrentsens_write_memory (mcurrentsens_t *ctx, uint8_t address, uint8_t *data_in, uint8_t len) |
| mCurrent Sens write memory function. | |
| err_t | mcurrentsens_read_memory (mcurrentsens_t *ctx, uint8_t address, uint8_t *data_out, uint8_t len) |
| mCurrent Sens read memory function. | |
| err_t | mcurrentsens_store_calib (mcurrentsens_t *ctx) |
| mCurrent Sens store calibration function. | |
| err_t | mcurrentsens_fetch_calib (mcurrentsens_t *ctx) |
| mCurrent Sens fetch calibration function. | |
| uint8_t | mcurrentsens_get_irq_pin (mcurrentsens_t *ctx) |
| mCurrent Sens get IRQ pin function. | |
| uint8_t | mcurrentsens_get_clk_pin (mcurrentsens_t *ctx) |
| mCurrent Sens get CLK pin function. | |
API for configuring and manipulating mCurrent Sens Click driver.
Any initialization code needed for MCU to function properly. Do not remove this line or clock might not be set correctly.
| float mcurrentsens_adc_to_mv | ( | int32_t | adc_code, |
| float | gain_adc ) |
mCurrent Sens convert ADC code to millivolts function.
This function converts signed ADC code to millivolt value.
| [in] | adc_code | : Signed ADC conversion code. |
| [in] | gain_adc | : ADC gain value. |
| err_t mcurrentsens_apply_calib | ( | mcurrentsens_t * | ctx, |
| mcurrentsens_calib_t | cal ) |
mCurrent Sens apply channel calibration function.
This function applies the specified channel calibration values.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | cal | : Channel calibration data. |
0 - Success, -1 - Error. | void mcurrentsens_calculate_calib | ( | mcurrentsens_calib_t * | calib, |
| float | offset_coeff, | ||
| float | target_1, | ||
| float | measured_1, | ||
| float | target_2, | ||
| float | measured_2 ) |
mCurrent Sens calculate calibration function.
This function calculates gain and offset calibration registers based on two-point linear calibration.
| [out] | calib | : Calibration structure. |
| [in] | offset_coeff | : Channel coefficient. |
| [in] | target_1 | : First reference value. |
| [in] | measured_1 | : Measured value at first point. |
| [in] | target_2 | : Second reference value. |
| [in] | measured_2 | : Measured value at second point. |
| void mcurrentsens_cfg_setup | ( | mcurrentsens_cfg_t * | cfg | ) |
mCurrent Sens configuration object setup function.
This function initializes Click configuration structure to initial values.
| [out] | cfg | : Click configuration structure. See mcurrentsens_cfg_t object definition for detailed explanation. |
| err_t mcurrentsens_check_com | ( | mcurrentsens_t * | ctx | ) |
mCurrent Sens communication check function.
This function verifies device communication by reading the RESERVED_16 register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
0 - Device detected, -1 - Communication error. | err_t mcurrentsens_default_cfg | ( | mcurrentsens_t * | ctx | ) |
mCurrent Sens default configuration function.
This function executes a default configuration of mCurrent Sens Click board.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
0 - Success, -1 - Error. See #err_t definition for detailed explanation. | err_t mcurrentsens_en_dig_cal | ( | mcurrentsens_t * | ctx, |
| uint8_t | en_offset, | ||
| uint8_t | en_gain ) |
mCurrent Sens enable digital calibration function.
This function enables or disables digital offset and gain calibration.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | en_offset | : Offset calibration enable setting. |
| [in] | en_gain | : Gain calibration enable setting. |
0 - Success, -1 - Error. | err_t mcurrentsens_fetch_calib | ( | mcurrentsens_t * | ctx | ) |
mCurrent Sens fetch calibration function.
This function reads calibration values from external EEPROM.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
0 - Success, -1 - Error. | uint8_t mcurrentsens_get_clk_pin | ( | mcurrentsens_t * | ctx | ) |
mCurrent Sens get CLK pin function.
This function reads the CLK pin logic state.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| err_t mcurrentsens_get_gain_cal | ( | mcurrentsens_t * | ctx, |
| uint32_t * | data_out ) |
mCurrent Sens get gain calibration function.
This function reads the GAINCAL register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where unsigned 24-bit gain calibration value will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_get_irq | ( | mcurrentsens_t * | ctx, |
| uint8_t * | data_out ) |
mCurrent Sens get IRQ function.
This function reads the IRQ register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where IRQ data will be stored. |
0 - Success, -1 - Error. | uint8_t mcurrentsens_get_irq_pin | ( | mcurrentsens_t * | ctx | ) |
mCurrent Sens get IRQ pin function.
This function reads the IRQ pin logic state.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| err_t mcurrentsens_get_offset_cal | ( | mcurrentsens_t * | ctx, |
| int32_t * | data_out ) |
mCurrent Sens get offset calibration function.
This function reads the OFFSETCAL register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where signed 24-bit offset calibration value will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_init | ( | mcurrentsens_t * | ctx, |
| mcurrentsens_cfg_t * | cfg ) |
mCurrent Sens initialization function.
This function initializes all necessary pins and peripherals used for this Click board.
| [out] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | cfg | : Click configuration structure. See mcurrentsens_cfg_t object definition for detailed explanation. |
0 - Success, -1 - Error. See #err_t definition for detailed explanation. | err_t mcurrentsens_read_adc | ( | mcurrentsens_t * | ctx, |
| int32_t * | data_out ) |
mCurrent Sens read ADC data function.
This function reads the signed 24-bit ADC conversion data.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where ADC data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_adc_avg | ( | mcurrentsens_t * | ctx, |
| uint8_t | sample_count, | ||
| int32_t * | data_out ) |
mCurrent Sens read averaged ADC function.
This function reads multiple ADC samples and returns averaged data.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | sample_count | : Number of samples. |
| [out] | data_out | : Pointer to memory location where averaged ADC data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_ch1_current | ( | mcurrentsens_t * | ctx, |
| float * | data_out ) |
mCurrent Sens read channel 1 current function.
This function reads channel 1 current measurement in mA.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where ADC data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_ch1_voltage | ( | mcurrentsens_t * | ctx, |
| float * | data_out ) |
mCurrent Sens read channel 1 voltage function.
This function reads channel 1 voltage measurement in mV.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where ADC data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_ch2_current | ( | mcurrentsens_t * | ctx, |
| float * | data_out ) |
mCurrent Sens read channel 2 current function.
This function reads channel 2 current measurement in mA.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where ADC data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_ch2_voltage | ( | mcurrentsens_t * | ctx, |
| float * | data_out ) |
mCurrent Sens read channel 2 voltage function.
This function reads channel 2 voltage measurement in mV.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where ADC data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_memory | ( | mcurrentsens_t * | ctx, |
| uint8_t | address, | ||
| uint8_t * | data_out, | ||
| uint8_t | len ) |
mCurrent Sens read memory function.
This function reads a sequence of bytes from the device memory over I2C, starting at the selected 8-bit address. The read length must not exceed the page size (16 bytes) and the transfer must not cross the device end address.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | address | : Start memory address (8-bit). |
| [out] | data_out | : Pointer to output data buffer. |
| [in] | len | : Number of bytes to read (max page size). |
0 - Success, -1 - Error. See #err_t definition for detailed explanation. | err_t mcurrentsens_read_reg | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint8_t * | data_out ) |
mCurrent Sens read register function.
This function reads a byte from the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Register address. |
| [out] | data_out | : Pointer to memory location where data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_reg16 | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint16_t * | data_out ) |
mCurrent Sens read 16-bit register function.
This function reads two bytes from the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Register address. |
| [out] | data_out | : Pointer to memory location where data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_reg24 | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint32_t * | data_out ) |
mCurrent Sens read 24-bit register function.
This function reads three bytes from the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Register address. |
| [out] | data_out | : Pointer to memory location where data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_regs | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint8_t * | data_out, | ||
| uint8_t | len ) |
mCurrent Sens read multiple registers function.
This function reads multiple bytes starting from the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Start register address. |
| [out] | data_out | : Pointer to output buffer. |
| [in] | len | : Number of bytes to read. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_temperature | ( | mcurrentsens_t * | ctx, |
| float * | data_out ) |
mCurrent Sens read temperature function.
This function reads internal temperature data.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [out] | data_out | : Pointer to memory location where temperature data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_read_voltage_avg | ( | mcurrentsens_t * | ctx, |
| uint8_t | sample_count, | ||
| float * | data_out ) |
mCurrent Sens read averaged voltage function.
This function reads ADC samples and converts them to millivolts.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | sample_count | : Number of samples. |
| [out] | data_out | : Pointer to memory location where voltage data will be stored. |
0 - Success, -1 - Error. | err_t mcurrentsens_send_fast_cmd | ( | mcurrentsens_t * | ctx, |
| uint8_t | cmd ) |
mCurrent Sens send fast command function.
This function sends a fast command to the device.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | cmd | : Fast command byte. |
0 - Success, -1 - Error. | err_t mcurrentsens_set_gain | ( | mcurrentsens_t * | ctx, |
| uint8_t | gain ) |
mCurrent Sens set gain function.
This function sets the programmable gain amplifier value.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | gain | : Gain setting. |
0 - Success, -1 - Error. | err_t mcurrentsens_set_gain_cal | ( | mcurrentsens_t * | ctx, |
| uint32_t | data_in ) |
mCurrent Sens set gain calibration function.
This function writes the GAINCAL register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | data_in | : Unsigned 24-bit gain calibration value. |
0 - Success, -1 - Error. | err_t mcurrentsens_set_mode | ( | mcurrentsens_t * | ctx, |
| uint8_t | mode ) |
mCurrent Sens set mode function.
This function sets the ADC operating mode.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | mode | : ADC operating mode setting. |
0 - Success, -1 - Error. | err_t mcurrentsens_set_mux | ( | mcurrentsens_t * | ctx, |
| uint8_t | vin_p, | ||
| uint8_t | vin_n ) |
mCurrent Sens set MUX function.
This function selects the positive and negative ADC input channels.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | vin_p | : Positive ADC input channel. |
| [in] | vin_n | : Negative ADC input channel. |
0 - Success, -1 - Error. | err_t mcurrentsens_set_offset_cal | ( | mcurrentsens_t * | ctx, |
| int32_t | data_in ) |
mCurrent Sens set offset calibration function.
This function writes the OFFSETCAL register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | data_in | : Signed 24-bit offset calibration value. |
0 - Success, -1 - Error. | err_t mcurrentsens_set_osr | ( | mcurrentsens_t * | ctx, |
| uint8_t | osr ) |
mCurrent Sens set OSR function.
This function sets the oversampling ratio.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | osr | : Oversampling ratio setting. |
0 - Success, -1 - Error. | err_t mcurrentsens_store_calib | ( | mcurrentsens_t * | ctx | ) |
mCurrent Sens store calibration function.
This function stores calibration values to external EEPROM.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
0 - Success, -1 - Error. | err_t mcurrentsens_wait_data_ready | ( | mcurrentsens_t * | ctx | ) |
mCurrent Sens wait data ready function.
This function waits until ADC conversion is complete.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
0 - Data ready, -1 - Timeout. | err_t mcurrentsens_write_memory | ( | mcurrentsens_t * | ctx, |
| uint8_t | address, | ||
| uint8_t * | data_in, | ||
| uint8_t | len ) |
mCurrent Sens write memory function.
This function writes a sequence of bytes to the device memory over I2C, starting at the selected 8-bit address. The write length must not exceed the page size (16 bytes) and the transfer must not cross the device end address.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | address | : Start memory address (8-bit). |
| [in] | data_in | : Pointer to input data buffer. |
| [in] | len | : Number of bytes to write (max page size). |
0 - Success, -1 - Error. See #err_t definition for detailed explanation. | err_t mcurrentsens_write_reg | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint8_t | data_in ) |
mCurrent Sens write register function.
This function writes a byte to the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Register address. |
| [in] | data_in | : Data to be written. |
0 - Success, -1 - Error. | err_t mcurrentsens_write_reg16 | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint16_t | data_in ) |
mCurrent Sens write 16-bit register function.
This function writes two bytes to the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Register address. |
| [in] | data_in | : 16-bit data to be written. |
0 - Success, -1 - Error. | err_t mcurrentsens_write_reg24 | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint32_t | data_in ) |
mCurrent Sens write 24-bit register function.
This function writes three bytes to the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Register address. |
| [in] | data_in | : 24-bit data to be written. |
0 - Success, -1 - Error. | err_t mcurrentsens_write_regs | ( | mcurrentsens_t * | ctx, |
| uint8_t | reg, | ||
| uint8_t * | data_in, | ||
| uint8_t | len ) |
mCurrent Sens write multiple registers function.
This function writes multiple bytes starting from the specified register.
| [in] | ctx | : Click context object. See mcurrentsens_t object definition for detailed explanation. |
| [in] | reg | : Start register address. |
| [in] | data_in | : Pointer to data buffer. |
| [in] | len | : Number of bytes to write. |
0 - Success, -1 - Error.